<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function formatDate(date, format) {
        var obj = {
            'yyyy': date.getFullYear(),
            'yy': ('' + date.getFullYear()).slice(-2),
            'MM': ('0' + (date.getMonth() + 1)).slice(-2),
            'M': date.getMonth() + 1,
            'dd': ('0' + date.getDate()).slice(-2),
            'd': date.getDate(),
            'HH': ('0' + date.getHours()).slice(-2),
            'H': date.getHours(),
            'hh': ('0' + date.getHours() % 12).slice(-2),
            'h': date.getHours() % 12,
            'mm': ('0' + date.getMinutes()).slice(-2),
            'm': date.getMinutes(),
            'ss': ('0' + date.getSeconds()).slice(-2),
            's': date.getSeconds(),
            'w': ['日', '一', '二', '三', '四', '五', '六'][date.getDay()]
        }
        return format.replace(/[a-z]+/ig, function (key) { return obj[key] });
        // for (let k in obj) {
        //     format = format.replace(k, obj[k]);
        // }
        // return format;
    }
    var res = formatDate(new Date(1409894060000), 'yyyy-MM-dd HH:mm:ss 星期w');
    console.log(res);

</script>

</html>